<?php
namespace Admin\Controller;
use Think\Controller;
class LoginController extends Controller {
    public function index(){

	    //p($_SESSION);
	    //p(I('SESSION.username'));die;
	    //if(!isset($_SESSION)){$this->redirect('/Admin/index');}
	    if(!I('session.username')=='samuel'){$this->redirect('/Admin/login');}
	    $this->display();
    }
    public function login(){
	    if(!IS_POST){$this->error('登录错误');}
	    $data=I();
	    $data['time']=date('Y-m-d');
	    //p($data);die;

	    $User=I();
	    //p($User['username']);
	    $Username = M('User')->getfield('username');
	    $Password = M('User')->getfield('password');
	    //p($Password);die;
	    //$User->create($data);
	    //if($User->add($data)) {
	    //p($Password);
	    //p(md5($User['password']));die;
	    //if($Username==$User['username'] && md5($Password)==md5($User['password'])) {
	    if($Username==$User['username'] && $Password==md5($User['password'])) {

		    $this->success('成功','/index.php/Admin/index');
		    session('username',$Username);
	    }

	    else
	    {
		    $this->error('失败','index',1);

	    }
 
	     
    }
}
